<%--
  Created by IntelliJ IDEA.
  User: 王鹏飞
  Date: 2020/7/21
  Time: 10:35
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
<jsp:include page="../common/menu.jsp" />

<html>
<head>
    <title>派车单管理</title>
</head>

<script src="<%=basePath%>js/tools.js"></script>
<body>
<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">派车单管理</li>
    </ul>
    <div class="layui-tab-content">
        <table class="layui-hide" id="backUser" lay-filter="backUser"></table>
    </div>
</div>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addUser">派车单生成</button>
    </div>
</script>

<script type="text/html" id="startTime">
    {{ dateFormat(d.startTime) }}
</script>

<script type="text/html" id="createTime">
    {{ dateFormat(d.createTime) }}
</script>
<script type="text/html" id="status">
    {{changeStatus(d.status)}}
</script>
<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="del">删除</a>
</script>
</body>
</html>
<jsp:include page="../common/js.jsp" />
<script type="text/javascript">

    $('document').ready(function() {
        var layer = null;
        var laypage = null;
        var table = null;
        var form = null;
        layui.use([ "laypage", "layer", 'table' ], function() {
            layer = layui.layer;
            laypage = layui.laypage;
            table = layui.table;
            form = layui.form;

            table.render({
                elem : '#backUser',
                url : '<%=basePath%>dispatch/dispatchListByCond',
                id : 'backUser',
                height:650,
                toolbar : '#toolbar',
                cellMinWidth : 100,
                cols : [ [
                    {
                        field : 'id',
                        title : '编号',
                        width : '5%',
                        unresize : true,
                        sort : true
                    }
                    , {
                        field : 'dispatchNum',
                        title : '单号',
                        width : '10%',
                        unresize : true,
                        sort : true
                    }
                    , {
                        field : 'status',
                        templet : '#status',
                        width : '13%',
                        align : 'center',
                        title : '状态'
                    }
                    , {
                        field : 'salesmanName',
                        title : '业务员',
                        width : '10%',
                        unresize : true
                    }
                    , {
                        field : 'companyName',
                        title : '用车单位',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'companyContactName',
                        title : '联系人',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'companyContactTel',
                        title : '联系电话',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'payType',
                        title : '支付类型',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'carType',
                        title : '所属类别',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'startTime',
                        title : '出车时间',
                        width : '10%',
                        templet : '#startTime',
                        sort : true
                    }
                    , {
                        field : 'startAddress',
                        title : '起始地点',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'vehicleNum',
                        title : '车牌号码',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'pilotName',
                        title : '驾驶员',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'totalMoney',
                        title : '租车费',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'saleMoney',
                        title : '折让金额',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'realMoney',
                        title : '实际金额',
                        width : '10%',
                        sort : true
                    }
                    , {
                        field : 'createTime',
                        title : '登记日期',
                        width : '10%',
                        templet : '#createTime',
                        sort : true
                    }
                    , {
                        field : 'remark',
                        title : '备注',
                        width : '12%',
                        unresize : true
                    }
                    , {
                        field : 'createBy',
                        title : '创建人',
                        width : '10%',
                        sort : true
                    }
                    , {
                        fixed:'right',
                        width:120 ,
                        align:'center',
                        toolbar:'#bar',
                        title:'操作'
                    }
                ] ],
                page : true
            });

            //头工具栏事件
            table.on('toolbar(backUser)', function(obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data;
                switch(obj.event){
                    case 'addUser':
                        window.location.href="<%=basePath %>dispatch/toAddDispatch";
                        break;
                };

            });

            //监听工具条
            table.on('tool(backUser)', function(obj){
                var data = obj.data;
                console.log(data)
                if(obj.event === 'edit'){
                    if(data.status == 1){
                        window.location.href="<%=basePath %>dispatch/toEditDispatch?id="+data.id;
                    }else{
                        layer.msg('此状态不允许修改！');
                    }
                }else if(obj.event === 'del'){
                    if(data.status == 1){
                        window.location.href="<%=basePath %>dispatch/delDispatch?id="+data.id;
                    }else{
                        layer.msg('此状态不允许删除！');
                    }
                }
            });

        });
    });

    function changeStatus(str) {
        var typeName = new Map();
        typeName.set(1, '未审核-未收款');
        typeName.set(2, '已审核-未收款');
        typeName.set(3, '已完成-已收款');
        typeName.set(0, '已取消');
        return typeName.get(str);
    }
</script>
